package com.clms.system.service.impl;

import com.clms.common.R;
import com.clms.system.mapper.StatisticsMapper;
import com.clms.system.service.StatisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collector;
import java.util.stream.Collectors;

/**
 * @program: clms-third
 * @description:
 * @author: 大鱼
 * @create: 2021-07-23 19:19
 **/
@Service
public class StatisticsServiceimpl implements StatisticsService {
    @Autowired
    StatisticsMapper statisticsMapper;
    @Override
    public R Bydiarystatistics() {
       List<Map> list= statisticsMapper.Bydiarystatistics();//获取对象Key:val
        List data = new ArrayList();//转换到前台是data数组
        List price = new ArrayList();//转换到前台是price数组
        System.out.println(list);
        for (Map map : list) {
            data.add(String.valueOf(map.get("end_time")));//根据key放到对应数组
            price.add(String.valueOf(map.get("total_price")));//根据key放到对应数组
         }
      Map chardata= new HashMap<>();
        chardata.put("data", data);//放入map前端解析chardata{data数组，price数组}
        chardata.put("price", price);

        return R.ok().put("chardata",chardata);
    }
}
